{% extends "layout.html" %}

{% block title %}Lancement facture{% endblock %}

{% block content %}
    <!-- script pour modif odre affichage -->
    <script type="text/javascript"> if (window.jQuery == undefined)
            document.write(unescape('%3Cscript src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"%3E%3C/script%3E'));</script>
    <script type="text/javascript" src="js/vendor/jquery.tablesorter.min.js"></script>
    <div class="span5">
        <table class="table table-hover">
            {% if not(session.niveauAuth=='2')and not(session.niveauAuth=='5')and not(session.niveauAuth=='6')and not(session.niveauAuth=='9') %}
                <tr>
                    <td>Facturation fixe </td>
                    <td><a href="facturation-fixe" class="btn btn-success pull-right"><i class="icon-white icon-refresh"></i> Lancement</a></td>
                </tr>
            {% endif %}
            {% if not(session.niveauAuth=='3')and not(session.niveauAuth=='6')and not(session.niveauAuth=='9') %}
                <tr>
                    <td>Facturation Mobile</td>
                    <td><a href="facturation-mobile" class="btn btn-success pull-right"><i class="icon-white icon-refresh"></i> Lancement</a></td>
                </tr>
                <tr>
                    <td>Téléchargement du CDR Mobile</td>
                    <td><a href="cdr-extraction?action=complet" class="btn btn-success pull-right"><i class="icon-white icon-refresh"></i> Lancement</a></td>
                </tr>
            {% endif %}
            {% if not(session.niveauAuth=='2')and not(session.niveauAuth=='5')and not(session.niveauAuth=='6')and not(session.niveauAuth=='9') %}
                <tr>
                    <td>Téléchargement des factures avant envoie</td>
                    <td><a href="zip-dossier.php?dossier={{facture.date|date("mY")}}" class="btn btn-success pull-right"><i class="icon-white icon-refresh"></i> Lancement</a></td>
                </tr>
            {% endif %}
        </table>
    </div>
    <!-- Deuxième colonne -->
    {% if not(session.niveauAuth=='6')and not(session.niveauAuth=='9') %}
        <div class="span6">
            <table class="table table-hover">
                <tr>
                    <td>Envoie facture par mail </td>
                    <td><a href="envoie-mail" class="btn btn-success pull-right"><i class="icon-white icon-refresh"></i> Envoyer</a></td>
                </tr>
                <tr>
                    <td>SEPA factures ponctuelles</td>
                    <td><a href="SEPA-factures-ponctuelles" class="btn btn-success pull-right"><i class="icon-white icon-refresh"></i> Lancement</a></td>
                </tr>
                <tr>
                    <td>SEPA Avoir factures ponctuelles</td>
                    <td><a href="SEPA-factures-ponctuelles-avoir" class="btn btn-success pull-right"><i class="icon-white icon-refresh"></i> Lancement</a></td>
                </tr>
                <tr>
                    <td>SEPA des anciens clients</td>
                    <td><a href="SEPA-factures&type=rcur" class="btn btn-success pull-right"><i class="icon-white icon-refresh"></i> Lancement</a></td>
                </tr>
                <tr>
                    <td>SEPA des nouveaux clients {% if nb_nouveaux_clients %}<span class='warning-new-clients'>Attention, il existe des nouveaux clients.</span>{% endif %}</td>
                    <td><a href="SEPA-factures" class="btn btn-{% if nb_nouveaux_clients %}warning confirm-new-client{% else %}success{% endif %} pull-right"><i class="icon-white icon-refresh"></i> Lancement</a></td>
                </tr>
            </table>
        </div>
    {% endif %}   
    <div class="row">
        <!-- tROISIEME colonne -->
        <div class="span11">
            <br />
            <legend>Récapitulatif facturations</legend>
            <table class="table table-striped tablesorter" id="myTable">
                <thead>
                    <tr>
                        <th>Nom prenom / Raison sociale{{session.niveauAuth}}</th>
                        <th>Type </th>
                        <th>Montant € HT</th>
                        <th>Montant € TTC</th>
                        <th>Date</th>
                        <th>Facture</th>
                        <th>Envoi</th>
                        <th>Détail</th>
                    </tr>
                </thead>
                {% for facture in factures %}
                    {% if session.niveauAuth=='1' or session.niveauAuth=='3' or session.niveauAuth=='5' %}
                        <tr>
                            <td>{{facture.nom}}{% if facture.type == 'ponctuelle'%} <a href="detail-facture-ponctuelle?id-facture={{ facture.id }}"><small>Détail</small></a>{% endif %}</td>
                            <td>{{facture.type}}</td>
                            <td align="right">{{facture.total_facturation|number_format(2,',', ' ')}}</td>
                            <td align="right">{{(facture.total_facturation*1.2) | number_format(2,',', ' ')}}</td>
                            <td>{{facture.date|date("d/m/Y")}}</td>
                            <td>{% if not facture.facture is empty %}<a href="{{facture.facture}}" target="_blank"><img src="img/pdf-logo.jpg" width="25px" /></a>{% endif %}</td>
                            <td> {% if facture.facture_envoi == 'ok' %}<img src="img/ok.jpg" width="25px" />{% endif %}</td>
                            <td>{% if facture.detail == 'oui' %}<a href="facture_temp/csv/{{ "now"|date("mY") }}/{{ facture.num_client }}_{{ "now"|date("mY") }}_regroup.csv" target="_blank"><img src="img/list.png" width="25px" /></a>{% endif %}</td>
                        </tr>
                    {% elseif facture.facture_envoi == 'ok' and (session.niveauAuth!='1' or session.niveauAuth!='5') %}
                        <tr>
                            <td>{{facture.nom}}</td>
                            <td>{{facture.type}} </td>
                            <td align="right">{{facture.total_facturation|number_format(2,',', ' ')}}</td>
                            <td align="right">{{(facture.total_facturation*1.2) | number_format(2,',', ' ')}}</td>
                            <td>{{facture.date|date("d/m/Y")}}</td>
                            <td><a href="{{facture.facture}}" target="_blank"><img src="img/pdf-logo.jpg" width="25px" /></a></td>
                            <td> {% if facture.facture_envoi == 'ok' %}<img src="img/ok.jpg" width="25px" />{% endif %}</td>
                            <td>{% if facture.detail == 'oui' %}<a href="facture_temp/csv/{{ "now"|date("mY") }}/{{ facture.num_client }}_{{ "now"|date("mY") }}_regroup.csv" target="_blank"><img src="img/list.png" width="25px" /></a>{% endif %}</td>
                        </tr>  
                    {% endif %}
                {% endfor %}						
            </table>
            {% if not(session.niveauAuth=='2' or session.niveauAuth=='5' or session.niveauAuth=='6' or session.niveauAuth=='9') %}
                <h4>
                    <center>
                        {% if not(session.niveauAuth=='3') %}
                            Total facturation mobile: {{total_mobile_ttc}} € TTC ({{total_mobile}} € HT)   -
                        {% endif %}
                        {% if not(session.niveauAuth=='2' or session.niveauAuth=='5' or session.niveauAuth=='6' or session.niveauAuth=='9') %} 
                            Total facturation fixe: {{total_fixe_ttc}} € TTC ({{total_fixe}} € HT)
                        {% endif %}
                        <br/><br/>
                        <p>

                        </p>
                    </center>
                </h4>
            {% endif %}
        </div>
    </div>
    <script  type="text/javascript">
        $(function() {
            $("#myTable").tablesorter();
        });
        $('.confirm-new-client').click(function() {
            var r = confirm('Attention, il existe des nouveaux clients dans la base, si vous confirmez l\'action, ceux-ci passerons en anciens clients. Assurez-vous d\'avoir généré le SEPA des anciens clients en premier. Confirmer ?');
            if (r === false) {
                return false;
            }else{
                $('span.warning-new-clients').remove();
                $(this).removeClass('btn-warning');
                $(this).removeClass('confirm-new-client');
                $(this).addClass('btn-success');
            }
        });
    </script>
{% endblock %}

